package binaryTree;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author kunkun
 * @className Test01
 * @Description ...
 * @date 2025/4/1 14:51
 */
public class LeetCode_124 {
    public class TreeNode {
       int val;
       TreeNode left;
       TreeNode right;
       TreeNode() {}
       TreeNode(int val) { this.val = val; }
       TreeNode(int val, TreeNode left, TreeNode right) {
           this.val = val;
           this.left = left;
           this.right = right;
       }
   }

    public int maxPathSum(TreeNode root) {
        solution_1(root);
        return result;
    }

    int result = Integer.MIN_VALUE;

    public int solution_1(TreeNode root){
        if (root == null){
            return 0;
        }
        int left = Math.max(0,solution_1(root.left));
        int right = Math.max(0,solution_1(root.right));

        result = Math.max(root.val+left+right,result);

        return Math.max(root.val+left,root.val+right);

    }




}
